package com.wfg.nettydemo.io.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

/**
 * @author wufagang
 * @description
 * @date 2022年05月28日 19:03
 */
public class NIOClient {
    public static void main(String[] args) throws IOException {
        SocketChannel socketChannel = SocketChannel.open();

        socketChannel.configureBlocking(false);

        if (!socketChannel.connect(new InetSocketAddress("127.0.0.1",7000))){

            while (!socketChannel.finishConnect()){
                System.out.println("因为链接需要事件，客户端不会阻塞，可以做其他工作");
            }
        }
        String str = "hello netty 学习！";
        ByteBuffer byteBuffer = ByteBuffer.wrap(str.getBytes());

        //发送数据
        socketChannel.write(byteBuffer);
        int read = System.in.read();

    }
}
